package com.fxb.concurrency.demo1;

/**
 * @author fangjiaxiaobai
 * @date 2021-03-01 10:08
 * @since 1.0.0
 */
public class DemoResource {

    private boolean isRunning = true;

    public void run() {

        String anyString = new String();
        int i = 0;
        while (isRunning) {
            // synchronized会使isRunning变成共享变量
            //            synchronized (anyString) {
            //
            //            }
            i++;
            // 没有输出(IO操作), 可以验证上面的结论
            //            System.out.println("running....");
        }

        System.out.println("停下来了!" + i);
    }

    public void stopRun() {
        System.out.println(Thread.currentThread().getName() + "--发送停止信号");
        this.isRunning = false;
    }
}
